package cn.edu.hqu.exp.courseselection.web;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.validation.Valid;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.validation.Errors;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.SessionAttribute;
import org.springframework.web.bind.annotation.SessionAttributes;

import cn.edu.hqu.exp.courseselection.domain.PersonInfo;
import lombok.extern.slf4j.Slf4j;

@SessionAttributes(value="person",types= {PersonInfo.class})
@Slf4j
@Controller
@RequestMapping("/personinfo")
public class PersonInfoController {
	@GetMapping
	public String personInfoForm(Model model) {
		model.addAttribute("personinfo", new PersonInfo());
		return "personal";
	}
	
	@PostMapping
	public String processPersoninfo(@Valid @ModelAttribute("personinfo") PersonInfo person,Errors errors) {
		if(errors.hasErrors()) {
			 return "personal";
		 }
		log.info("个人信息:"+person);
		return "redirect:/course";
	}
}
